//package com.dji.sdk.self.internal.controller;
//
//import android.content.ComponentName;
//import android.content.Intent;
//import android.content.ServiceConnection;
//import android.content.SharedPreferences;
//import android.graphics.Color;
//import android.os.Bundle;
//
//
//import android.os.Handler;
//import android.os.IBinder;
//import android.os.Looper;
//import android.os.Message;
//import android.text.TextUtils;
//import android.util.Log;
//import android.view.WindowManager;
//import android.widget.TextView;
//
//import com.amap.api.maps2d.AMap;
//import com.amap.api.maps2d.AMapOptions;
//import com.amap.api.maps2d.CameraUpdate;
//import com.amap.api.maps2d.CameraUpdateFactory;
//import com.amap.api.maps2d.MapView;
//import com.amap.api.maps2d.UiSettings;
//import com.amap.api.maps2d.model.BitmapDescriptorFactory;
//import com.amap.api.maps2d.model.LatLng;
//import com.amap.api.maps2d.model.Marker;
//import com.amap.api.maps2d.model.MarkerOptions;
//import com.amap.api.maps2d.model.Polyline;
//import com.amap.api.maps2d.model.PolylineOptions;
//import com.dji.sdk.self.R;
//import com.dji.sdk.self.internal.model.UavCondition;
//import com.dji.sdk.self.internal.services.SendService;
//import com.dji.sdk.self.internal.utils.ToastUtils;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import dji.common.flightcontroller.FlightControllerState;
//import dji.sdk.airlink.OcuSyncLink;
//import dji.sdk.airlink.WiFiLink;
//import dji.sdk.base.BaseProduct;
//import dji.sdk.battery.Battery;
//import dji.sdk.camera.Camera;
//import dji.sdk.flightcontroller.FlightController;
//import dji.sdk.flightcontroller.RTK;
//import dji.sdk.products.Aircraft;
//import dji.sdk.remotecontroller.RemoteController;
//import dji.sdk.sdkmanager.DJISDKManager;
//import dji.sdk.sdkmanager.LiveStreamManager;
//import dji.ux.widget.controls.CameraControlsWidget;
//
////, View.OnClickListener
//public class UXSDKActivity extends BaseActivity implements AMap.OnMapClickListener{
//
//    private static final String FLAG_CONNECTION_CHANGE = "dji_sdk_connection_change";
//    private static BaseProduct mProduct;
//
//    private MapView mapView;
//    private AMap aMap;
//    private double latitude=181 , longitude=181 ;
//    private Marker droneMarker = null;
//    private TextView textView;
//    private FlightController mFlightController;//
//    private Battery battery;//电池
//    private RemoteController remoteController;//遥控器
//    private RTK rtk;
//    private WiFiLink wiFiLink;
//    private BaseProduct product;
//
//    private TextView tvLiveState;
//
//    private CameraControlsWidget widget;
//    private Camera camera;
//
//
//    private double pitch;
//    private double roll;
//    private double yaw;
//    private double height;
//    private float distance;
//    private double horizontalSpeed;
//    private float verticalSpeed;
//    private int voltage;
//    private int current;
//    private float batteryTemp;
//    private int batteryCapacity;//电池容量
//    private int uavPower;//飞机电量
//    private int remotePower;
//    private int remoteSignal;
//    private int graphSignal;
//    private String serialNumber;
//    private UavCondition uavCondition;
////    private OkhttpConnection connection;
//
//
//    private float fps;
//
//    Thread mThread;
//    private Handler mHandler ;
//    private List<LatLng> latLngs = new ArrayList<LatLng>();
//    private Polyline polyline;
//
//    public static synchronized BaseProduct getProductInstance() {
//        if (null == mProduct) {
//            mProduct = DJISDKManager.getInstance().getProduct();
//        }
//        return mProduct;
//    }
//
//
//
//    //推流
//    private LiveStreamManager.OnLiveChangeListener listener;
//    private LiveStreamManager.LiveStreamVideoSource currentVideoSource = LiveStreamManager.LiveStreamVideoSource.Primary;
//    private GetUrl getUrl;
//    private String streamUrl;
//    private SharedPreferences preferences;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); //隐藏状态栏
//        setContentView(R.layout.activity_uxsdk);
//        product = DJISDKManager.getInstance().getProduct();
//        listener = new LiveStreamManager.OnLiveChangeListener() {
//            @Override
//            public void onStatusChanged(int i) {
//                ToastUtils.setResultToToast("status changed : " + i);
//            }
//        };
//
//        mapView = findViewById(R.id.map);
//        mapView.onCreate(savedInstanceState);
//        tvLiveState = findViewById(R.id.tv_live_state);
//        preferences = getSharedPreferences("LiveStreamUrl",0);
//        String temp = preferences.getString("liveUrl",null);
//        BaseProduct product = DJISDKManager.getInstance().getProduct();
//        if (product!=null&&product.isConnected()){
//            if(product instanceof Aircraft){
//                FlightController flightController = ((Aircraft) product).getFlightController();
//                flightController.setStateCallback(new FlightControllerState.Callback() {
//                    @Override
//                    public void onUpdate(FlightControllerState flightControllerState) {
//                        latitude = flightControllerState.getAircraftLocation().getLatitude();
//                        longitude = flightControllerState.getAircraftLocation().getLongitude();
//                        updateDroneLocation();
//                    }
//                });
//            }
//        }
//        if(!TextUtils.isEmpty(temp)){
//            streamUrl = temp;
//            startLiveShow();
//        }
//
//
//        mHandler = new Handler(Looper.getMainLooper()){
//            @Override
//            public void handleMessage(Message msg) {
//                if(msg.what == 100){
//                    ToastUtils.setResultToToast("handleMessage in UXSDKActivity\n uavCondition is:"+uavCondition);
//                }
//            }
//        };
//
//        initMapView();
//    }
//
//
//    public void initMapView(){
//        if (aMap == null) {
//            aMap = mapView.getMap();
//            aMap.getMaxZoomLevel();
//            aMap.setOnMapClickListener(this);// add the listener for click for amap object
//            UiSettings settings = aMap.getUiSettings();
//            settings.setZoomControlsEnabled(false);
//            settings.setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT);
//
//        }
//        LatLng nanjing = new LatLng(32.041544, 118.767413);
//        aMap.addMarker(new MarkerOptions().position(nanjing).title("Marker in Nanjing"));
//        aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(nanjing,20));
//
//    }
//
//
//    void startLiveShow() {
//        if (!isLiveStreamManagerOn()) {
//            return;
//        }
//        if (DJISDKManager.getInstance().getLiveStreamManager().isStreaming()) {
//            ToastUtils.setResultToToast("already started!");
//            return;
//        }
//
//        new Thread() {
//            @Override
//            public void run() {
//                Log.i("UrlStreamService2",streamUrl);
//                streamUrl = "rtmp://10.2.13.194:1935/live/13000";
//                DJISDKManager.getInstance().getLiveStreamManager().setLiveUrl(streamUrl);
//                int result = DJISDKManager.getInstance().getLiveStreamManager().startStream();
//                DJISDKManager.getInstance().getLiveStreamManager().setStartTime();
//                if(DJISDKManager.getInstance().getLiveStreamManager().isStreaming()){
//                    fps = DJISDKManager.getInstance().getLiveStreamManager().getLiveVideoFps();
//                    tvLiveState.setText("正在推流"+fps+"fps");
//                }
//                ToastUtils.setResultToToast("startLive:" + result +
//                        "\n isVideoStreamSpeedConfigurable:" + DJISDKManager.getInstance().getLiveStreamManager().isVideoStreamSpeedConfigurable() +
//                        "\n isLiveAudioEnabled:" + DJISDKManager.getInstance().getLiveStreamManager().isLiveAudioEnabled());
//                Log.i("UXSDKActivity","startLive:" + result +
//                        "\n isVideoStreamSpeedConfigurable:" + DJISDKManager.getInstance().getLiveStreamManager().isVideoStreamSpeedConfigurable() +
//                        "\n isLiveAudioEnabled:" + DJISDKManager.getInstance().getLiveStreamManager().isLiveAudioEnabled());
//            }
//        }.start();
//    }
//
//    private boolean isLiveStreamManagerOn() {
//        if (DJISDKManager.getInstance().getLiveStreamManager() == null) {
//            ToastUtils.setResultToToast("No live stream manager!");
//            return false;
//        }
//        return true;
//    }
//
//    @Override
//    public void onMapClick(LatLng latLng) {
////        Intent intent = new Intent(UXSDKActivity.this,GaodeMapActivity.class);
////        startActivity(intent);
//        this.finish();
//
//    }
//
//
//    private void updateDroneLocation(){
//        LatLng pos = new LatLng(latitude, longitude);
//        latLngs.add(pos);
//        //Create MarkerOptions object
//        final MarkerOptions markerOptions = new MarkerOptions();
//        markerOptions.position(pos);
//        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.aircraft));
//
//        runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
//                if (droneMarker != null) {
//                    droneMarker.remove();
//
//                }
//
//                if (checkGpsCoordination(latitude, longitude)) {
//                    droneMarker = aMap.addMarker(markerOptions);
//                    polyline =aMap.addPolyline(new PolylineOptions().
//                            addAll(latLngs).width(10).color(Color.argb(255, 1, 1, 1)));
//                    cameraUpdate();
//                }
//            }
//        });
//    }
//    public static boolean checkGpsCoordination(double latitude, double longitude) {
//        return (latitude > -90 && latitude < 90 && longitude > -180 && longitude < 180) && (latitude != 0f && longitude != 0f);
//    }
//    private void cameraUpdate(){
//        LatLng pos = new LatLng(latitude, longitude);
//        float zoomlevel = (float) 20.0;
//        CameraUpdate cu = CameraUpdateFactory.newLatLngZoom(pos, zoomlevel);
//        aMap.moveCamera(cu);
//
//    }
//
//
//    @Override
//    protected void onSaveInstanceState(Bundle outState) {
//        super.onSaveInstanceState(outState);
//        //在activity执行onSaveInstanceState时执行mMapView.onSaveInstanceState (outState)，保存地图当前的状态
//        mapView.onSaveInstanceState(outState);
//    }
//
//
//
//    @Override
//    public void onAttachedToWindow() {
//        super.onAttachedToWindow();
//        BaseProduct product = DJISampleApplication.getProductInstance();
//        if (product == null || !product.isConnected()) {
//            ToastUtils.setResultToToast("Disconnect");
//            return;
//        }
//        if (isLiveStreamManagerOn()){
//            DJISDKManager.getInstance().getLiveStreamManager().registerListener(listener);
//        }
//    }
//
//    @Override
//    public void onDetachedFromWindow() {
//        super.onDetachedFromWindow();
//        if (isLiveStreamManagerOn()){
//            DJISDKManager.getInstance().getLiveStreamManager().unregisterListener(listener);
//        }
//    }
//
//
//    @Override
//    protected void onDestroy(){
//        super.onDestroy();
//        mapView.onDestroy();
//        //unregisterReceiver(mReceiver);
//    }
//    @Override
//    protected void onResume() {
//        super.onResume();
//        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
//        mapView.onResume();
//        Aircraft aircraft = (Aircraft) DJISampleApplication.getProductInstance();
//
//        if(aircraft!=null&&aircraft.isConnected()){
//            ToastUtils.showToast(aircraft.toString());
//            if (isLiveStreamManagerOn()) {
//                ToastUtils.setResultToToast("already started!");
//                if(DJISDKManager.getInstance().getLiveStreamManager().isStreaming()){
//                    fps = DJISDKManager.getInstance().getLiveStreamManager().getLiveVideoFps();
//                    tvLiveState.setText("正在推流"+fps+"fps");
//                }
//                return;
//            }
//        }
//    }
//    @Override
//    protected void onPause() {
//        super.onPause();
//        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
//        mapView.onPause();
//    }
//
//    @Override
//    public void onBackPressed() {
//        super.onBackPressed();
////        Intent intent = new Intent(UXSDKActivity.this,GaodeMapActivity.class);
////        startActivity(intent);
//        this.finish();
//
//    }
//}
//
//
